﻿using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

using log4net;
namespace AnyOffice.general.system.workflow.flow_form
{  

    public partial class form_import : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["form_id"] == null) ? 0 : int.Parse(Request.QueryString["form_id"].ToString());
                this.ViewState["FormId"] = num;
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                if (this.fileHtml.PostedFile.ContentLength > 0)
                {
                    string str = string.Empty;
                    try
                    {
                        if ((this.fileHtml.PostedFile.ContentType == "text/plain") || (this.fileHtml.PostedFile.ContentType == "text/html"))
                        {
                            Stream inputStream = this.fileHtml.PostedFile.InputStream;
                            if (inputStream.CanRead)
                            {
                                byte[] buffer = new byte[this.fileHtml.PostedFile.ContentLength];
                                inputStream.Read(buffer, 0, this.fileHtml.PostedFile.ContentLength);
                                str = Encoding.Default.GetString(buffer);
                            }
                        }
                        FlowFormTypeDao dao = new FlowFormTypeDao();
                        FlowFormTypeData ollO = new FlowFormTypeData();
                        ollO.FormId = Convert.ToInt32(this.ViewState["FormId"].ToString());
                        ollO.FormModel = str;
                        dao.UpdateModel(base.Conn, ollO);
                        this.litMessage.Text = base.ShowPrompt("导入表单成功！", "index.aspx");
                    }
                    catch (Exception exception)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("", exception);
                        }
                        this.litMessage.Text = base.ShowPrompt("导入表单失败！", "index.aspx");
                    }
                }
            }
        }
    }
}

